package com.xmh.reptile.main;

import org.junit.Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;

public class ChanDaoReptile {

    public static void main(String[] args) {
        String url = "http://192.168.14.206/zentao/task-delete-101-";// 402
//		String url = "http://192.168.14.206/zentao/task-delete-24-";// 402

        //http://192.168.14.206/zentao/task-delete-24-340-yes.html

        String urlEnd = "-yes.html";// 402

        int ids[] = {1521, 1525, 1526, 1518, 1519, 1512, 1513, 1514, 1515, 1516, 1517, 1595,};

        for (int i : ids) {
            doGet(url + i + urlEnd);
        }
    }

    public static String doGet(String httpurl) {
        HttpURLConnection connection = null;
        InputStream is = null;
        BufferedReader br = null;
        String result = null;// 返回结果字符串
        try {
            // 创建远程url连接对象
            URL url = new URL(httpurl);
            // 通过远程url连接对象打开一个连接，强转成httpURLConnection类
            connection = (HttpURLConnection) url.openConnection();
            // 设置连接方式：get
            connection.setRequestMethod("GET");
            // 设置连接主机服务器的超时时间：15000毫秒
            connection.setConnectTimeout(15000);
            // 设置读取远程返回的数据时间：60000毫秒
            connection.setReadTimeout(60000);

            connection.setRequestProperty("Cookie",
                    "device=desktop; selfClose=0; keepLogin=on; theme=pink; pagerBugBrowse=200; ajax_lastNext=on; checkedItem=452%2C743%2C799%2C881%2C890%2C899%2C905; pagerProductBrowse=100; preBranch=0; ajax_dragSelected=on; from=product; lastStoryModule=655; preProductID=1; lastTaskModule=634; za=xiaominghui; zp=f9c0db17068a7ec8ec721880008d7607d54fb1e2; lastProduct=82; moduleBrowseParam=0; productBrowseParam=0; storyModuleParam=0; storyProductParam=0; storyBranchParam=0; projectTaskOrder=pri_asc; storyPreProjectID=101; projectStoryOrder=order_desc; lastProject=101; preProjectID=101; windowWidth=1920; windowHeight=506; zentaosid=v9ob0p7v6d87q6tds3abbjt6g0");

            // 发送请求
            connection.connect();
            // 通过connection连接，获取输入流
            if (connection.getResponseCode() == 200) {
                is = connection.getInputStream();
                // 封装输入流is，并指定字符集
                br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                // 存放数据
                StringBuffer sbf = new StringBuffer();
                String temp = null;
                while ((temp = br.readLine()) != null) {
                    sbf.append(temp);
                    sbf.append("\r\n");
                }
                result = sbf.toString();
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 关闭资源
            if (null != br) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if (null != is) {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            connection.disconnect();// 关闭远程连接
        }

        return result;
    }


    @Test
    public void chandao2() throws InterruptedException {
        String ids = "1618\n" +
                "1604\n" +
                "1583\n" +
                "1579\n" +
                "1578\n" +
                "1523\n" +
                "1489\n" +
                "1473\n" +
                "1466\n" +
                "1244\n" +
                "1243\n" +
                "1242\n" +
                "1076\n" +
                "1070\n" +
                "1027\n" +
                "952\n" +
                "920\n" +
                "918\n" +
                "469\n" +
                "459\n" +
                "43\n";

        String strat = "http://192.168.14.206/zentao/story-view-";

        String end = "-1-project-114.html";

        Arrays.asList(ids.split("\n")).forEach(e -> System.out.println(strat + e + end));
    }


//		String urlPath = "你的请求链接";
//		String cookie = "要发送的cookie";
//		URL url = new URL(urlPath);
//		URLConnection conn = url.openConnection();
//		conn.setRequestProperty("Cookie", cookie);
//		conn.setDoInput(true);
//		BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
//		StringBuilder sb = new StringBuilder();
//		String line = null;
//		while ((line = br.readLine()) != null) {
//			sb.append(line);
//		}
//		System.out.println("请求响应结果：" + sb);
}
//、、另外，所有人都以为无忧城外并没有多少凶险啊，谁知道居然潜伏着如此恐怖的剧毒枯藤蛇？